// Admin Dataset

// 2016

use "$Baseline_dtRaw/admin/escolas16.dta", clear

gen version = 16

order version

lab var version "Version of form used"

label variable escola_id "School ID"
label variable regime_de_ensino "Type of school"
label variable nome_da_escola "School name"
label variable n_da_escola "School number"
label variable numero_de_turnos_na_escola "Number of parts of the day with classes"
label variable ultima_classe_ensinada_na_escola "Highest class taught"
label variable n_de_horas_por_turno "Duration class periods (in hours)"

label variable director "School director name"
label variable idade_director "Director age"
label variable n_de_telefone "Director phone number"
label variable nivel_academico_d "Director education"
label variable especialidade_d "Director speciality"
label variable nome_do_sub_director_pedagogico "Deputy director name"
label variable nivel_academico_sd "Deputy director education"
label variable especialidade_sd "Deputy director speciality"

label variable n_de_horas_como_director_d "Director hours dedicated to director duties"
label variable n_de_horas_como_director_sd "Deputy director hours dedicated to director duties"
label variable n_de_horas_como_docente_d "Director hours dedicated to teaching"
label variable n_de_horas_como_docente_sd "Deputy director hours dedicated to teaching"

label variable data_dia "Date of completing the form (DAY)"
label variable data_mes "Date of completing the form (MONTH)"
label variable data_ano "Date of completing the form (YEAR)"

rename escola_id 							school_id
rename regime_de_ensino  					school_type
rename nome_da_escola  						school_name
rename n_da_escola  						school_number
rename numero_de_turnos_na_escola  			number_periods
rename ultima_classe_ensinada_na_escola  	highest_grade
rename n_de_horas_por_turno		  			period_hours
rename director  				 			director_name
rename idade_director  						director_age
rename n_de_telefone  						director_tel
rename nivel_academico_d  					director_edu
rename especialidade_d  					director_spec
rename nome_do_sub_director_pedagogico  	deputy_name
rename nivel_academico_sd  					deputy_edu
rename especialidade_sd  					deputy_spec
rename n_de_horas_como_director_d  			director_hoursdir
rename n_de_horas_como_director_sd  		deputy_hoursdir
rename n_de_horas_como_docente_d  			director_hoursteach
rename n_de_horas_como_docente_sd  			deputy_hoursteach
rename data_dia  							date_day
rename data_mes  							date_month
rename data_ano								date_year

drop ano school_type school_number

replace highest_grade = . if highest_grade==99

replace number_periods = . if number_periods==9

replace period_hours = . if inlist(period_hours,8,9)
replace period_hours = 4.5 if period_hours==4.3

*** figure out why 3.3 and 4.3 are not being replaced

foreach var in director_name director_edu director_spec deputy_name deputy_edu deputy_spec{
replace `var' = "" if `var'=="999                           "
replace `var' = "" if `var'=="999                 "
}

replace director_age=. if director_age==99

replace director_tel = . if director_tel==999

foreach var in director_hoursdir deputy_hoursdir director_hoursteach deputy_hoursteach{
replace `var' = . if `var'==99
}

replace director_hoursdir = . if director_hoursdir==0 & director_hoursteach==0
replace director_hoursteach = . if director_hoursdir==. & director_hoursteach==0

replace deputy_hoursdir = . if deputy_hoursdir==0 & deputy_hoursteach==0
replace deputy_hoursteach = . if deputy_hoursdir==. & deputy_hoursteach==0

replace date_day = . if date_day==99
replace date_month = . if date_month==99
replace date_year = 2017

****************************************
************** QUADRO1 *****************
****************************************

forval x=5/14{
lab var tot_mf_`x'_1 "Number of students pre-school age `x'"
lab var tot_mf_`x'_2 "Number of students grade 1 age `x'"
lab var tot_mf_`x'_3 "Number of students grade 2 age `x'"
lab var tot_mf_`x'_4 "Number of students grade 3 age `x'"
lab var tot_mf_`x'_5 "Number of students grade 4 age `x'"
lab var tot_mf_`x'_6 "Number of students grade 5 age `x'"
lab var tot_mf_`x'_7 "Number of students grade 6 age `x'"

lab var tot_f_`x'_1 "Number of girls pre-school age `x'"
lab var tot_f_`x'_2 "Number of girls grade 1 age `x'"
lab var tot_f_`x'_3 "Number of girls grade 2 age `x'"
lab var tot_f_`x'_4 "Number of girls grade 3 age `x'"
lab var tot_f_`x'_5 "Number of girls grade 4 age `x'"
lab var tot_f_`x'_6 "Number of girls grade 5 age `x'"
lab var tot_f_`x'_7 "Number of girls grade 6 age `x'"
}

rename tot_mf_(#)_1 students_pre_age(#)
rename tot_mf_(#)_2 students_g1_age(#)
rename tot_mf_(#)_3 students_g2_age(#)
rename tot_mf_(#)_4 students_g3_age(#)
rename tot_mf_(#)_5 students_g4_age(#)
rename tot_mf_(#)_6 students_g5_age(#)
rename tot_mf_(#)_7 students_g6_age(#)

rename tot_mf_(##)_1 students_pre_age(##)
rename tot_mf_(##)_2 students_g1_age(##)
rename tot_mf_(##)_3 students_g2_age(##)
rename tot_mf_(##)_4 students_g3_age(##)
rename tot_mf_(##)_5 students_g4_age(##)
rename tot_mf_(##)_6 students_g5_age(##)
rename tot_mf_(##)_7 students_g6_age(##)

rename tot_f_(#)_1 girls_pre_age(#)
rename tot_f_(#)_2 girls_g1_age(#)
rename tot_f_(#)_3 girls_g2_age(#)
rename tot_f_(#)_4 girls_g3_age(#)
rename tot_f_(#)_5 girls_g4_age(#)
rename tot_f_(#)_6 girls_g5_age(#)
rename tot_f_(#)_7 girls_g6_age(#)

rename tot_f_(##)_1 girls_pre_age(##)
rename tot_f_(##)_2 girls_g1_age(##)
rename tot_f_(##)_3 girls_g2_age(##)
rename tot_f_(##)_4 girls_g3_age(##)
rename tot_f_(##)_5 girls_g4_age(##)
rename tot_f_(##)_6 girls_g5_age(##)
rename tot_f_(##)_7 girls_g6_age(##)

egen students_pre = rowtotal(students_pre_age5 students_pre_age6 students_pre_age7 students_pre_age8 students_pre_age9 students_pre_age10 students_pre_age11 students_pre_age12 students_pre_age13 students_pre_age14), missing
egen girls_pre = rowtotal(girls_pre_age5 girls_pre_age6 girls_pre_age7 girls_pre_age8 girls_pre_age9 girls_pre_age10 girls_pre_age11 girls_pre_age12 girls_pre_age13 girls_pre_age14), missing

forval x=1/6{
egen students_g`x' = rowtotal(students_g`x'_age5 students_g`x'_age6 students_g`x'_age7 students_g`x'_age8 students_g`x'_age9 students_g`x'_age10 students_g`x'_age11 students_g`x'_age12 students_g`x'_age13 students_g`x'_age14), missing
egen girls_g`x' = rowtotal(girls_g`x'_age5 girls_g`x'_age6 girls_g`x'_age7 girls_g`x'_age8 girls_g`x'_age9 girls_g`x'_age10 girls_g`x'_age11 girls_g`x'_age12 girls_g`x'_age13 girls_g`x'_age14), missing
}

egen students = rowtotal(students_pre students_g1 students_g2 students_g3 students_g4 students_g5 students_g6)
egen girls = rowtotal(girls_pre girls_g1 girls_g2 girls_g3 girls_g4 girls_g5 girls_g6)



lab var students_pre 	"Number of students in pre-school"
lab var girls_pre  		"Number of girls in pre-school"
lab var students_g1  	"Number of students in grade 1"
lab var girls_g1  		"Number of girls in grade 1"
lab var students_g2  	"Number of students in grade 2"
lab var girls_g2  		"Number of girls in grade 2"
lab var students_g3  	"Number of students in grade 3"
lab var girls_g3  		"Number of girls in grade 3"
lab var students_g4 	"Number of students in grade 4"
lab var girls_g4  		"Number of girls in grade 4"
lab var students_g5  	"Number of students in grade 5"
lab var girls_g5  		"Number of girls in grade 5"
lab var students_g6  	"Number of students in grade 6"
lab var girls_g6  		"Number of girls in grade 6"
lab var students  		"Number of students in total"
lab var girls 			"Number of girls in total"


order students_pre girls_pre students_g1 girls_g1 students_g2 girls_g2 students_g3 girls_g3 students_g4 girls_g4 students_g5 girls_g5 students_g6 girls_g6 students girls, after(girls_g6_age14)

****************************************
************** QUADRO3 *****************
****************************************

label variable n_de_turmas_1 "Number of pre-school classes"
label variable n_de_turmas_2 "Number of 1st grade classes"
label variable n_de_turmas_3 "Number of 2nd grade classes"
label variable n_de_turmas_4 "Number of 3rd grade classes"
label variable n_de_turmas_5 "Number of 4th grade classes"
label variable n_de_turmas_6 "Number of 5th grade classes"
label variable n_de_turmas_7 "Number of 6th grade classes"

label variable n_de_turnos_1 "Number periods the pre-school classes or divided over"
label variable n_de_turnos_2 "Number periods the 1st grade classes or divided over"
label variable n_de_turnos_3 "Number periods the 2nd grade classes or divided over"
label variable n_de_turnos_4 "Number periods the 3rd grade classes or divided over"
label variable n_de_turnos_5 "Number periods the 4th grade classes or divided over"
label variable n_de_turnos_6 "Number periods the 5th grade classes or divided over"
label variable n_de_turnos_7 "Number periods the 6th grade classes or divided over"

foreach var in n_de_turnos_1 n_de_turnos_2 n_de_turnos_3 n_de_turnos_4 n_de_turnos_5 n_de_turnos_6 n_de_turnos_7{
replace `var' = . if `var'==99
}

rename n_de_turmas_1 		classes_pre
rename n_de_turmas_2 		classes_g1
rename n_de_turmas_3  		classes_g2
rename n_de_turmas_4   		classes_g3
rename n_de_turmas_5   		classes_g4
rename n_de_turmas_6   		classes_g5
rename n_de_turmas_7   		classes_g6

rename n_de_turnos_1   		periods_pre
rename n_de_turnos_2    	periods_g1
rename n_de_turnos_3    	periods_g2
rename n_de_turnos_4    	periods_g3
rename n_de_turnos_5    	periods_g4
rename n_de_turnos_6    	periods_g5
rename n_de_turnos_7   		periods_g6

egen classes = rowtotal(classes_pre classes_g1 classes_g2 classes_g3 classes_g4 classes_g5 classes_g6), missing

lab var classes "Number of classes in total"

order classes ,after(classes_g6)


****************************************
************** QUADRO1B ****************
****************************************

foreach var in tot_mf_a_1 tot_mf_a_2 tot_mf_a_3 tot_mf_a_4 tot_mf_a_5 tot_mf_a_6 tot_f_a_1 tot_f_a_2 tot_f_a_3 tot_f_a_4 tot_f_a_5 tot_f_a_6{
replace `var' = . if `var'==999
}

foreach var in nec_mf_vis_1 nec_mf_vis_2 nec_mf_vis_3 nec_mf_vis_4 nec_mf_vis_5 nec_mf_vis_6 nec_mf_vis_7 nec_f_vis_1 nec_f_vis_2 nec_f_vis_3 nec_f_vis_4 nec_f_vis_5 nec_f_vis_6 nec_f_vis_7 nec_mf_aud_1 nec_mf_aud_2 nec_mf_aud_3 nec_mf_aud_4 nec_mf_aud_5 nec_mf_aud_6 nec_mf_aud_7 nec_f_aud_1 nec_f_aud_2 nec_f_aud_3 nec_f_aud_4 nec_f_aud_5 nec_f_aud_6 nec_f_aud_7 nec_mf_mot_1 nec_mf_mot_2 nec_mf_mot_3 nec_mf_mot_4 nec_mf_mot_5 nec_mf_mot_6 nec_mf_mot_7 nec_f_mot_1 nec_f_mot_2 nec_f_mot_3 nec_f_mot_4 nec_f_mot_5 nec_f_mot_6 nec_f_mot_7 nec_mf_out_1 nec_mf_out_2 nec_mf_out_3 nec_mf_out_4 nec_mf_out_5 nec_mf_out_6 nec_mf_out_7 nec_f_out_1 nec_f_out_2 nec_f_out_3 nec_f_out_4 nec_f_out_5 nec_f_out_6 nec_f_out_7{
replace `var' = . if `var'==99
}

rename tot_mf_a_1 repeaters_g1
rename tot_mf_a_2 repeaters_g2
rename tot_mf_a_3 repeaters_g3
rename tot_mf_a_4 repeaters_g4
rename tot_mf_a_5 repeaters_g5
rename tot_mf_a_6 repeaters_g6

rename tot_f_a_1 repeatgirl_g1
rename tot_f_a_2 repeatgirl_g2
rename tot_f_a_3 repeatgirl_g3
rename tot_f_a_4 repeatgirl_g4
rename tot_f_a_5 repeatgirl_g5
rename tot_f_a_6 repeatgirl_g6

egen repeaters = rowtotal(repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 repeaters_g5 repeaters_g6), missing
egen repeatgirl = rowtotal(repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 repeatgirl_g4 repeatgirl_g5 repeatgirl_g6), missing

lab var repeaters_g1  	"Number of repeaters in grade 1"
lab var repeatgirl_g1  	"Number of repeating girls in grade 1"
lab var repeaters_g2  	"Number of repeaters in grade 2"
lab var repeatgirl_g2  	"Number of repeating girls in grade 2"
lab var repeaters_g3  	"Number of repeaters in grade 3"
lab var repeatgirl_g3  	"Number of repeating girls in grade 3"
lab var repeaters_g4 	"Number of repeaters in grade 4"
lab var repeatgirl_g4  	"Number of repeating girls in grade 4"
lab var repeaters_g5  	"Number of repeaters in grade 5"
lab var repeatgirl_g5  	"Number of repeating girls in grade 5"
lab var repeaters_g6  	"Number of repeaters in grade 6"
lab var repeatgirl_g6  	"Number of repeating girls in grade 6"
lab var repeaters  		"Number of repeaters in total"
lab var repeatgirl 		"Number of repeating girls in total"

order repeaters repeatgirl, after(repeatgirl_g6)

****************************************
************** QUADRO4 *****************
****************************************


label variable nec_mf_vis_1 "Number of students with visual disability in pre-school"
label variable nec_mf_vis_2 "Number of students with visual disability in grade 1"
label variable nec_mf_vis_3 "Number of students with visual disability in grade 2"
label variable nec_mf_vis_4 "Number of students with visual disability in grade 3"
label variable nec_mf_vis_5 "Number of students with visual disability in grade 4"
label variable nec_mf_vis_6 "Number of students with visual disability in grade 5"
label variable nec_mf_vis_7 "Number of students with visual disability in grade 6"

label variable nec_f_vis_1 "Number of girls with visual disability in pre-school"
label variable nec_f_vis_2 "Number of girls with visual disability in grade 1"
label variable nec_f_vis_3 "Number of girls with visual disability in grade 2"
label variable nec_f_vis_4 "Number of girls with visual disability in grade 3"
label variable nec_f_vis_5 "Number of girls with visual disability in grade 4"
label variable nec_f_vis_6 "Number of girls with visual disability in grade 5"
label variable nec_f_vis_7 "Number of girls with visual disability in grade 6"

label variable nec_mf_aud_1 "Number of students with auditory disability in pre-school"
label variable nec_mf_aud_2 "Number of students with auditory disability in grade 1"
label variable nec_mf_aud_3 "Number of students with auditory disability in grade 2"
label variable nec_mf_aud_4 "Number of students with auditory disability in grade 3"
label variable nec_mf_aud_5 "Number of students with auditory disability in grade 4"
label variable nec_mf_aud_6 "Number of students with auditory disability in grade 5"
label variable nec_mf_aud_7 "Number of students with auditory disability in grade 6"

label variable nec_f_aud_1 "Number of girls with auditory disability in pre-school"
label variable nec_f_aud_2 "Number of girls with auditory disability in grade 1"
label variable nec_f_aud_3 "Number of girls with auditory disability in grade 2"
label variable nec_f_aud_4 "Number of girls with auditory disability in grade 3"
label variable nec_f_aud_5 "Number of girls with auditory disability in grade 4"
label variable nec_f_aud_6 "Number of girls with auditory disability in grade 5"
label variable nec_f_aud_7 "Number of girls with auditory disability in grade 6"

label variable nec_mf_mot_1 "Number of students with motor disability in pre-school"
label variable nec_mf_mot_2 "Number of students with motor disability in grade 1"
label variable nec_mf_mot_3 "Number of students with motor disability in grade 2"
label variable nec_mf_mot_4 "Number of students with motor disability in grade 3"
label variable nec_mf_mot_5 "Number of students with motor disability in grade 4"
label variable nec_mf_mot_6 "Number of students with motor disability in grade 5"
label variable nec_mf_mot_7 "Number of students with motor disability in grade 6"

label variable nec_f_mot_1 "Number of girls with motor disability in pre-school"
label variable nec_f_mot_2 "Number of girls with motor disability in grade 1"
label variable nec_f_mot_3 "Number of girls with motor disability in grade 2"
label variable nec_f_mot_4 "Number of girls with motor disability in grade 3"
label variable nec_f_mot_5 "Number of girls with motor disability in grade 4"
label variable nec_f_mot_6 "Number of girls with motor disability in grade 5"
label variable nec_f_mot_7 "Number of girls with motor disability in grade 6"

label variable nec_mf_out_1 "Number of students with other disability in pre-school"
label variable nec_mf_out_2 "Number of students with other disability in grade 1"
label variable nec_mf_out_3 "Number of students with other disability in grade 2"
label variable nec_mf_out_4 "Number of students with other disability in grade 3"
label variable nec_mf_out_5 "Number of students with other disability in grade 4"
label variable nec_mf_out_6 "Number of students with other disability in grade 5"
label variable nec_mf_out_7 "Number of students with other disability in grade 6"

label variable nec_f_out_1 "Number of girls with other disability in pre-school"
label variable nec_f_out_2 "Number of girls with other disability in grade 1"
label variable nec_f_out_3 "Number of girls with other disability in grade 2"
label variable nec_f_out_4 "Number of girls with other disability in grade 3"
label variable nec_f_out_5 "Number of girls with other disability in grade 4"
label variable nec_f_out_6 "Number of girls with other disability in grade 5"
label variable nec_f_out_7 "Number of girls with other disability in grade 6"

rename nec_mf_vis_1 	disabled_visual_pre
rename nec_mf_vis_2  	disabled_visual_g1
rename nec_mf_vis_3  	disabled_visual_g2
rename nec_mf_vis_4  	disabled_visual_g3
rename nec_mf_vis_5  	disabled_visual_g4
rename nec_mf_vis_6  	disabled_visual_g5
rename nec_mf_vis_7  	disabled_visual_g6

rename nec_f_vis_1  	disabgirl_visual_pre
rename nec_f_vis_2  	disabgirl_visual_g1
rename nec_f_vis_3  	disabgirl_visual_g2
rename nec_f_vis_4  	disabgirl_visual_g3
rename nec_f_vis_5  	disabgirl_visual_g4
rename nec_f_vis_6  	disabgirl_visual_g5
rename nec_f_vis_7  	disabgirl_visual_g6

rename nec_mf_aud_1  	disabled_audio_pre
rename nec_mf_aud_2  	disabled_audio_g1
rename nec_mf_aud_3  	disabled_audio_g2
rename nec_mf_aud_4  	disabled_audio_g3
rename nec_mf_aud_5  	disabled_audio_g4
rename nec_mf_aud_6  	disabled_audio_g5
rename nec_mf_aud_7  	disabled_audio_g6

rename nec_f_aud_1  	disabgirl_audio_pre
rename nec_f_aud_2  	disabgirl_audio_g1
rename nec_f_aud_3  	disabgirl_audio_g2
rename nec_f_aud_4  	disabgirl_audio_g3
rename nec_f_aud_5  	disabgirl_audio_g4
rename nec_f_aud_6  	disabgirl_audio_g5
rename nec_f_aud_7  	disabgirl_audio_g6

rename nec_mf_mot_1  	disabled_motor_pre
rename nec_mf_mot_2  	disabled_motor_g1
rename nec_mf_mot_3  	disabled_motor_g2
rename nec_mf_mot_4  	disabled_motor_g3
rename nec_mf_mot_5  	disabled_motor_g4
rename nec_mf_mot_6  	disabled_motor_g5
rename nec_mf_mot_7  	disabled_motor_g6

rename nec_f_mot_1  	disabgirl_motor_pre
rename nec_f_mot_2  	disabgirl_motor_g1
rename nec_f_mot_3  	disabgirl_motor_g2
rename nec_f_mot_4  	disabgirl_motor_g3
rename nec_f_mot_5  	disabgirl_motor_g4
rename nec_f_mot_6  	disabgirl_motor_g5
rename nec_f_mot_7  	disabgirl_motor_g6

rename nec_mf_out_1  	disabled_other_pre
rename nec_mf_out_2  	disabled_other_g1
rename nec_mf_out_3  	disabled_other_g2
rename nec_mf_out_4  	disabled_other_g3
rename nec_mf_out_5  	disabled_other_g4
rename nec_mf_out_6  	disabled_other_g5
rename nec_mf_out_7  	disabled_other_g6

rename nec_f_out_1  	disabgirl_other_pre
rename nec_f_out_2  	disabgirl_other_g1
rename nec_f_out_3  	disabgirl_other_g2
rename nec_f_out_4  	disabgirl_other_g3
rename nec_f_out_5  	disabgirl_other_g4
rename nec_f_out_6  	disabgirl_other_g5
rename nec_f_out_7 		disabgirl_other_g6

egen disabled_pre = rowtotal(disabled_visual_pre disabled_audio_pre disabled_motor_pre disabled_other_pre), missing
egen disabgirl_pre = rowtotal(disabgirl_visual_pre disabgirl_audio_pre disabgirl_motor_pre disabgirl_other_pre), missing


forval x=1/6{
egen disabled_g`x' = rowtotal(disabled_visual_g`x' disabled_audio_g`x' disabled_motor_g`x' disabled_other_g`x'), missing
egen disabgirl_g`x' = rowtotal(disabgirl_visual_g`x' disabgirl_audio_g`x' disabgirl_motor_g`x' disabgirl_other_g`x'), missing
}

egen disabled_visual = rowtotal(disabled_visual_pre disabled_visual_g1 disabled_visual_g2 disabled_visual_g3 disabled_visual_g4 disabled_visual_g5 disabled_visual_g6), missing
egen disabgirl_visual = rowtotal(disabgirl_visual_pre disabgirl_visual_g1 disabgirl_visual_g2 disabgirl_visual_g3 disabgirl_visual_g4 disabgirl_visual_g5 disabgirl_visual_g6), missing

egen disabled_audio = rowtotal(disabled_audio_pre disabled_audio_g1 disabled_audio_g2 disabled_audio_g3 disabled_audio_g4 disabled_audio_g5 disabled_audio_g6), missing
egen disabgirl_audio = rowtotal(disabgirl_audio_pre disabgirl_audio_g1 disabgirl_audio_g2 disabgirl_audio_g3 disabgirl_audio_g4 disabgirl_audio_g5 disabgirl_audio_g6), missing

egen disabled_motor = rowtotal(disabled_motor_pre disabled_motor_g1 disabled_motor_g2 disabled_motor_g3 disabled_motor_g4 disabled_motor_g5 disabled_motor_g6), missing
egen disabgirl_motor = rowtotal(disabgirl_motor_pre disabgirl_motor_g1 disabgirl_motor_g2 disabgirl_motor_g3 disabgirl_motor_g4 disabgirl_motor_g5 disabgirl_motor_g6), missing

egen disabled_other = rowtotal(disabled_other_pre disabled_other_g1 disabled_other_g2 disabled_other_g3 disabled_other_g4 disabled_other_g5 disabled_other_g6), missing
egen disabgirl_other = rowtotal(disabgirl_other_pre disabgirl_other_g1 disabgirl_other_g2 disabgirl_other_g3 disabgirl_other_g4 disabgirl_other_g5 disabgirl_other_g6), missing

egen disabled = rowtotal(disabled_visual disabled_audio disabled_motor disabled_other), missing
egen disabgirl = rowtotal(disabgirl_visual disabgirl_audio disabgirl_motor disabgirl_other), missing

order disabled_pre disabgirl_pre disabled_g1 disabgirl_g1 disabled_g2 disabgirl_g2 disabled_g3 disabgirl_g3 disabled_g4 disabgirl_g4 disabled_g5 disabgirl_g5 disabled_g6 disabgirl_g6 disabled_visual disabgirl_visual disabled_audio disabgirl_audio disabled_motor disabgirl_motor disabled_other disabgirl_other disabled disabgirl, after(disabgirl_other_g6)

lab var disabled_pre 		"Number of disabled students in pre-school"
lab var disabgirl_pre 	 	"Number of disabled girls in pre-school"
lab var disabled_g1  		"Number of disabled students in grade 1"
lab var disabgirl_g1  		"Number of disabled girls in grade 1"
lab var disabled_g2  		"Number of disabled students in grade 2"
lab var disabgirl_g2  		"Number of disabled girls in grade 2"
lab var disabled_g3  		"Number of disabled students in grade 3"
lab var disabgirl_g3  		"Number of disabled girls in grade 3"
lab var disabled_g4 		"Number of disabled students in grade 4"
lab var disabgirl_g4  		"Number of disabled girls in grade 4"
lab var disabled_g5  		"Number of disabled students in grade 5"
lab var disabgirl_g5  		"Number of disabled girls in grade 5"
lab var disabled_g6  		"Number of disabled students in grade 6"
lab var disabgirl_g6  		"Number of disabled girls in grade 6"
lab var disabled  			"Number of disabled students in total"
lab var disabgirl 			"Number of disabled girls in total"

lab var disabled_visual 	"Number of students with visual disability"
lab var disabgirl_visual  	"Number of girls with visual disability"
lab var disabled_audio  	"Number of students with auditory disability"
lab var disabgirl_audio  	"Number of girls with auditory disability"
lab var disabled_motor  	"Number of students with motor disability"
lab var disabgirl_motor  	"Number of girls with motor disability"
lab var disabled_other  	"Number of students with other disability"
lab var disabgirl_other 	"Number of girls with other disability"

****************************************
************** QUADRO5 *****************
****************************************

label variable nivprof_mf_6_ini_1 "Pre-school teachers education: until grade 6"
label variable nivprof_mf_6_ini_2 "Pre-school teachers education: until grade 6 without pedagogical training"
label variable nivprof_f_6_ini_1 "Pre-school female teachers education: until grade 6"
label variable nivprof_f_6_ini_2 "Pre-school female teachers education: until grade 6 without pedagogical training"

label variable nivprof_mf_9_ini_1 "Pre-school teachers education: grade 7-8"
label variable nivprof_mf_9_ini_2 "Pre-school teachers education: grade 7-8  without pedagogical training"
label variable nivprof_f_9_ini_1 "Pre-school female teachers education: grade 7-8 "
label variable nivprof_f_9_ini_2 "Pre-school female teachers education: grade 7-8  without pedagogical training"

label variable nivprof_mf_11_ini_1 "Pre-school teachers education: grade 9-10"
label variable nivprof_mf_11_ini_2 "Pre-school teachers education: grade 9-10  without pedagogical training"
label variable nivprof_f_11_ini_1 "Pre-school female teachers education: grade 9-10 "
label variable nivprof_f_11_ini_2 "Pre-school female teachers education: grade 9-10  without pedagogical training"

label variable nivprof_mf_13_ini_1 "Pre-school teachers education: grade 11-13"
label variable nivprof_mf_13_ini_2 "Pre-school teachers education: grade 11-13  without pedagogical training"
label variable nivprof_f_13_ini_1 "Pre-school female teachers education: grade 11-13 "
label variable nivprof_f_13_ini_2 "Pre-school female teachers education: grade 11-13  without pedagogical training"

label variable nivprof_mf_bach_ini_1 "Pre-school teachers education: bachelor"
label variable nivprof_mf_bach_ini_2 "Pre-school teachers education: bachelor  without pedagogical training"
label variable nivprof_f_bach_ini_1 "Pre-school female teachers education: bachelor "
label variable nivprof_f_bach_ini_2 "Pre-school female teachers education: bachelor  without pedagogical training"

label variable nivprof_mf_lic_ini_1 "Pre-school teachers education: graduated or more"
label variable nivprof_mf_lic_ini_2 "Pre-school teachers education: graduated or more  without pedagogical training"
label variable nivprof_f_lic_ini_1 "Pre-school female teachers education: graduated or more "
label variable nivprof_f_lic_ini_2 "Pre-school female teachers education: graduated or more  without pedagogical training"


label variable nivprof_mf_6_1 "Primary school teachers education: until grade 6"
label variable nivprof_mf_6_2 "Primary school teachers education: until grade 6 without pedagogical training"
label variable nivprof_f_6_1 "Primary school female teachers education: until grade 6"
label variable nivprof_f_6_2 "Primary school female teachers education: until grade 6 without pedagogical training"

label variable nivprof_mf_9_1 "Primary school teachers education: grade 7-8"
label variable nivprof_mf_9_2 "Primary school teachers education: grade 7-8 without pedagogical training"
label variable nivprof_f_9_1 "Primary school female teachers education: grade 7-8"
label variable nivprof_f_9_2 "Primary school female teachers education: grade 7-8 without pedagogical training"

label variable nivprof_mf_11_1 "Primary school teachers education: grade 9-10"
label variable nivprof_mf_11_2 "Primary school teachers education: grade 9-10 without pedagogical training"
label variable nivprof_f_11_1 "Primary school female teachers education: grade 9-10"
label variable nivprof_f_11_2 "Primary school female teachers education: grade 9-10 without pedagogical training"

label variable nivprof_mf_13_1 "Primary school teachers education: grade 11-13"
label variable nivprof_mf_13_2 "Primary school teachers education: grade 11-13 without pedagogical training"
label variable nivprof_f_13_1 "Primary school female teachers education: grade 11-13"
label variable nivprof_f_13_2 "Primary school female teachers education: grade 11-13 without pedagogical training"

label variable nivprof_mf_bach_1 "Primary school teachers education: bachelor"
label variable nivprof_mf_bach_2 "Primary school teachers education: bachelor without pedagogical training"
label variable nivprof_f_bach_1 "Primary school female teachers education: bachelor"
label variable nivprof_f_bach_2 "Primary school female teachers education: bachelor without pedagogical training"

label variable nivprof_mf_lic_1 "Primary school teachers education: graduated or more"
label variable nivprof_mf_lic_2 "Primary school teachers education: graduated or more  without pedagogical training"
label variable nivprof_f_lic_1 "Primary school female teachers education: graduated or more "
label variable nivprof_f_lic_2 "Primary school female teachers education: graduated or more  without pedagogical training"



foreach var in nivprof_mf_6_ini_1 nivprof_mf_6_ini_2 nivprof_f_6_ini_1 nivprof_f_6_ini_2 nivprof_mf_9_ini_1 nivprof_mf_9_ini_2 nivprof_f_9_ini_1 nivprof_f_9_ini_2 nivprof_mf_11_ini_1 nivprof_mf_11_ini_2 nivprof_f_11_ini_1 nivprof_f_11_ini_2 nivprof_mf_13_ini_1 nivprof_mf_13_ini_2 nivprof_f_13_ini_1 nivprof_f_13_ini_2 nivprof_mf_bach_ini_1 nivprof_mf_bach_ini_2 nivprof_f_bach_ini_1 nivprof_f_bach_ini_2 nivprof_mf_lic_ini_1 nivprof_mf_lic_ini_2 nivprof_f_lic_ini_1 nivprof_f_lic_ini_2 nivprof_mf_6_1 nivprof_mf_6_2 nivprof_f_6_1 nivprof_f_6_2 nivprof_mf_9_1 nivprof_mf_9_2 nivprof_f_9_1 nivprof_f_9_2 nivprof_mf_11_1 nivprof_mf_11_2 nivprof_f_11_1 nivprof_f_11_2 nivprof_mf_13_1 nivprof_mf_13_2 nivprof_f_13_1 nivprof_f_13_2 nivprof_mf_bach_1 nivprof_mf_bach_2 nivprof_f_bach_1 nivprof_f_bach_2 nivprof_mf_lic_1 nivprof_mf_lic_2 nivprof_f_lic_1 nivprof_f_lic_2{
replace `var' = . if `var'==99
}

rename nivprof_mf_9_ini_1 	nivprof_mf_7x_ini_1
rename nivprof_mf_9_ini_2  	nivprof_mf_7x_ini_2
rename nivprof_f_9_ini_1  	nivprof_f_7x_ini_1
rename nivprof_f_9_ini_2  	nivprof_f_7x_ini_2
rename nivprof_mf_11_ini_1  nivprof_mf_9_ini_1
rename nivprof_mf_11_ini_2  nivprof_mf_9_ini_2
rename nivprof_f_11_ini_1  	nivprof_f_9_ini_1
rename nivprof_f_11_ini_2  	nivprof_f_9_ini_2
rename nivprof_mf_13_ini_1  nivprof_mf_11_ini_1
rename nivprof_mf_13_ini_2  nivprof_mf_11_ini_2
rename nivprof_f_13_ini_1  	nivprof_f_11_ini_1
rename nivprof_f_13_ini_2  	nivprof_f_11_ini_2
rename nivprof_mf_9_1  		nivprof_mf_7x_1
rename nivprof_mf_9_2  		nivprof_mf_7x_2
rename nivprof_f_9_1  		nivprof_f_7x_1
rename nivprof_f_9_2  		nivprof_f_7x_2
rename nivprof_mf_11_1  	nivprof_mf_9_1
rename nivprof_mf_11_2  	nivprof_mf_9_2
rename nivprof_f_11_1  		nivprof_f_9_1
rename nivprof_f_11_2  		nivprof_f_9_2
rename nivprof_mf_13_1  	nivprof_mf_11_1
rename nivprof_mf_13_2  	nivprof_mf_11_2
rename nivprof_f_13_1  		nivprof_f_11_1
rename nivprof_f_13_2		nivprof_f_11_2

rename nivprof*_1 nivprof*

egen teachers_pre_until13 = rowtotal(nivprof_mf_6_ini nivprof_mf_6_ini_2 nivprof_mf_7x_ini nivprof_mf_7x_ini_2 nivprof_mf_9_ini nivprof_mf_9_ini_2 nivprof_mf_11_ini nivprof_mf_11_ini_2), missing
egen teachfem_pre_until13 = rowtotal(nivprof_f_6_ini nivprof_f_6_ini_2 nivprof_f_7x_ini nivprof_f_7x_ini_2 nivprof_f_9_ini nivprof_f_9_ini_2 nivprof_f_11_ini nivprof_f_11_ini_2), missing

egen teachers_pre_uni = rowtotal(nivprof_mf_bach_ini nivprof_mf_bach_ini_2 nivprof_mf_lic_ini nivprof_mf_lic_ini_2), missing
egen teachfem_pre_uni = rowtotal(nivprof_f_bach_ini nivprof_f_bach_ini_2 nivprof_f_lic_ini nivprof_f_lic_ini_2), missing

egen teachers_pre2 = rowtotal(teachers_pre_until13 teachers_pre_uni), missing
egen teachfem_pre2 = rowtotal(teachfem_pre_until13 teachfem_pre_uni), missing

egen teachers_prim_until13 = rowtotal(nivprof_mf_6 nivprof_mf_6_2 nivprof_mf_7x nivprof_mf_7x_2 nivprof_mf_9 nivprof_mf_9_2 nivprof_mf_11 nivprof_mf_11_2), missing
egen teachfem_prim_until13 = rowtotal(nivprof_f_6 nivprof_f_6_2 nivprof_f_7x nivprof_f_7x_2 nivprof_f_9 nivprof_f_9_2 nivprof_f_11 nivprof_f_11_2), missing

egen teachers_prim_uni = rowtotal(nivprof_mf_bach nivprof_mf_bach_2 nivprof_mf_lic nivprof_mf_lic_2), missing
egen teachfem_prim_uni = rowtotal(nivprof_f_bach nivprof_f_bach_2 nivprof_f_lic nivprof_f_lic_2), missing

egen teachers_prim2 = rowtotal(teachers_prim_until13 teachers_prim_uni), missing
egen teachfem_prim2 = rowtotal(teachfem_prim_until13 teachfem_prim_uni), missing

egen teachers_uni = rowtotal(teachers_pre_uni teachers_prim_uni), missing
egen teachfem_uni = rowtotal(teachfem_pre_uni teachfem_prim_uni), missing

egen teachers2 = rowtotal(teachers_prim2 teachers_pre2), missing
egen teachfem2 = rowtotal(teachfem_prim2 teachfem_pre2), missing

gen teachers_share_uni = teachers_uni/teachers2
gen teachfem_share_uni = teachfem_uni/teachfem2

drop teachers_pre_until13 teachfem_pre_until13 teachers_pre_uni teachfem_pre_uni teachers_pre2 teachfem_pre2 teachers_prim_until13 teachfem_prim_until13 teachers_prim_uni teachfem_prim_uni teachers_prim2 teachfem_prim2 teachers_uni teachfem_uni teachers2 teachfem2


****************************************
************** QUADRO6 *****************
****************************************

foreach var in idadeprof_mf_ini_1 idadeprof_mf_ini_2 idadeprof_mf_ini_3 idadeprof_mf_ini_4 idadeprof_mf_ini_5 idadeprof_mf_ini_6 idadeprof_f_ini_1 idadeprof_f_ini_2 idadeprof_f_ini_3 idadeprof_f_ini_4 idadeprof_f_ini_5 idadeprof_f_ini_6 idadeprof_mf_ep_1 idadeprof_mf_ep_2 idadeprof_mf_ep_3 idadeprof_mf_ep_4 idadeprof_mf_ep_5 idadeprof_mf_ep_6 idadeprof_f_ep_1 idadeprof_f_ep_2 idadeprof_f_ep_3 idadeprof_f_ep_4 idadeprof_f_ep_5 idadeprof_f_ep_6{
replace `var' = . if `var'==99
}

label variable idadeprof_mf_ini_1 "Number of pre-school teachers age: 18-19"
label variable idadeprof_mf_ini_2 "Number of pre-school teachers age: 20-24"
label variable idadeprof_mf_ini_3 "Number of pre-school teachers age: 25-29"
label variable idadeprof_mf_ini_4 "Number of pre-school teachers age: 30-34"
label variable idadeprof_mf_ini_5 "Number of pre-school teachers age: 35-39"
label variable idadeprof_mf_ini_6 "Number of pre-school teachers age: 40+"

label variable idadeprof_f_ini_1 "Number of pre-school female teachers age: 18-19"
label variable idadeprof_f_ini_2 "Number of pre-school female teachers age: 20-24"
label variable idadeprof_f_ini_3 "Number of pre-school female teachers age: 25-29"
label variable idadeprof_f_ini_4 "Number of pre-school female teachers age: 30-34"
label variable idadeprof_f_ini_5 "Number of pre-school female teachers age: 35-39"
label variable idadeprof_f_ini_6 "Number of pre-school female teachers age: 40+"

label variable idadeprof_mf_ep_1 "Number of primary school teachers age: 18-19"
label variable idadeprof_mf_ep_2 "Number of primary school teachers age: 20-24"
label variable idadeprof_mf_ep_3 "Number of primary school teachers age: 25-29"
label variable idadeprof_mf_ep_4 "Number of primary school teachers age: 30-34"
label variable idadeprof_mf_ep_5 "Number of primary school teachers age: 35-39"
label variable idadeprof_mf_ep_6 "Number of primary school teachers age: 40+"

label variable idadeprof_f_ep_1 "Number of primary school female teachers age: 18-19"
label variable idadeprof_f_ep_2 "Number of primary school female teachers age: 20-24"
label variable idadeprof_f_ep_3 "Number of primary school female teachers age: 25-29"
label variable idadeprof_f_ep_4 "Number of primary school female teachers age: 30-34"
label variable idadeprof_f_ep_5 "Number of primary school female teachers age: 35-39"
label variable idadeprof_f_ep_6 "Number of primary school female teachers age: 40+"


egen teachers_pre = rowtotal(idadeprof_mf_ini_1 idadeprof_mf_ini_2 idadeprof_mf_ini_3 idadeprof_mf_ini_4 idadeprof_mf_ini_5 idadeprof_mf_ini_6), missing
egen teachfem_pre = rowtotal(idadeprof_f_ini_1 idadeprof_f_ini_2 idadeprof_f_ini_3 idadeprof_f_ini_4 idadeprof_f_ini_5 idadeprof_f_ini_6), missing

egen teachers_prim = rowtotal(idadeprof_mf_ep_1 idadeprof_mf_ep_2 idadeprof_mf_ep_3 idadeprof_mf_ep_4 idadeprof_mf_ep_5 idadeprof_mf_ep_6), missing
egen teachfem_prim = rowtotal(idadeprof_f_ep_1 idadeprof_f_ep_2 idadeprof_f_ep_3 idadeprof_f_ep_4 idadeprof_f_ep_5 idadeprof_f_ep_6), missing


rename idadeprof_mf_ini_1 	teachers_age18_pre
rename idadeprof_mf_ini_2  	teachers_age20_pre
rename idadeprof_mf_ini_3  	teachers_age25_pre
rename idadeprof_mf_ini_4  	teachers_age30_pre
rename idadeprof_mf_ini_5  	teachers_age35_pre
rename idadeprof_mf_ini_6  	teachers_age40_pre

rename idadeprof_f_ini_1  	teachfem_age18_pre
rename idadeprof_f_ini_2   	teachfem_age20_pre
rename idadeprof_f_ini_3   	teachfem_age25_pre
rename idadeprof_f_ini_4   	teachfem_age30_pre
rename idadeprof_f_ini_5   	teachfem_age35_pre
rename idadeprof_f_ini_6   	teachfem_age40_pre

rename idadeprof_mf_ep_1   	teachers_age18_prim
rename idadeprof_mf_ep_2   	teachers_age20_prim
rename idadeprof_mf_ep_3   	teachers_age25_prim
rename idadeprof_mf_ep_4    teachers_age30_prim
rename idadeprof_mf_ep_5    teachers_age35_prim
rename idadeprof_mf_ep_6    teachers_age40_prim

rename idadeprof_f_ep_1 	teachfem_age18_prim
rename idadeprof_f_ep_2  	teachfem_age20_prim
rename idadeprof_f_ep_3  	teachfem_age25_prim
rename idadeprof_f_ep_4  	teachfem_age30_prim
rename idadeprof_f_ep_5  	teachfem_age35_prim
rename idadeprof_f_ep_6 	teachfem_age40_prim

lab var teachers_pre 	"Number of pre-school teachers"
lab var teachfem_pre 	"Number of pre-school female teachers"
lab var teachers_prim 	"Number of primary school teachers"
lab var teachfem_prim	"Number of primary school female teachers"

order teachers_pre teachfem_pre teachers_prim teachfem_prim, after(teachfem_age40_prim)

egen teachers = rowtotal(teachers_pre teachers_prim)
egen teachfem = rowtotal(teachfem_pre teachfem_prim)

****************************************
************** QUADRO7 *****************
****************************************

label variable aux_mf_1 "Number of secretaries"
label variable aux_mf_2 "Number of guards"
label variable aux_mf_3 "Number of cleaning assistants"
label variable aux_mf_4 "Number of teachers without class"
label variable aux_mf_5 "Number of other employees"

label variable aux_f_1 "Number of female secretaries"
label variable aux_f_2 "Number of female guards"
label variable aux_f_3 "Number of female cleaning assistants"
label variable aux_f_4 "Number of female teachers without class"
label variable aux_f_5 "Number of female other employees"

rename aux_mf_1 secretaries
rename aux_mf_2 guards
rename aux_mf_3 cleaners
rename aux_mf_4 other_teachers
rename aux_mf_5 other_empl
rename aux_f_1  secretaries_fem
rename aux_f_2  guards_fem
rename aux_f_3  cleaners_fem
rename aux_f_4  other_teachers_fem
rename aux_f_5  other_empl_fem

****************************************
************** QUADRO8A ****************
****************************************

foreach var in salas_blocos_1 salas_blocos_2 salas_blocos_3 salas_cimento_1 salas_cimento_2 salas_cimento_3 salas_outros_1 salas_outros_2 salas_outros_3{
replace `var' = . if `var'==99
}

label variable salas_blocos_1 "Number of classrooms: definite structure, prefrabricated blocks"
label variable salas_blocos_2 "Number of classrooms: provisional structure, prefrabricated blocks"
label variable salas_blocos_3 "Number of classrooms: improvised structure, prefrabricated blocks"

label variable salas_cimento_1 "Number of classrooms: definite structure, cement or bricks"
label variable salas_cimento_2 "Number of classrooms: provisional structure, cement or bricks"
label variable salas_cimento_3 "Number of classrooms: improvised structure, cement or bricks"

label variable salas_outros_1 "Number of classrooms: definite structure, other materials"
label variable salas_outros_2 "Number of classrooms: provisional structure, other materials"
label variable salas_outros_3 "Number of classrooms: improvised structure, other materials"

rename salas_blocos_1 	classrooms_def_blocks
rename salas_blocos_2 	classrooms_prov_blocks
rename salas_blocos_3 	classrooms_impr_blocks

rename salas_cimento_1 	classrooms_def_cement
rename salas_cimento_2 	classrooms_prov_cement
rename salas_cimento_3 	classrooms_impr_cement

rename salas_outros_1 	classrooms_def_other
rename salas_outros_2 	classrooms_prov_other
rename salas_outros_3	classrooms_impr_other

egen classrooms_def = rowtotal(classrooms_def_blocks classrooms_def_cement classrooms_def_other), missing
egen classrooms_prov = rowtotal(classrooms_prov_blocks classrooms_prov_cement classrooms_prov_other), missing
egen classrooms_impr = rowtotal(classrooms_impr_blocks classrooms_impr_cement classrooms_impr_other), missing

egen classrooms = rowtotal(classrooms_def_blocks classrooms_prov_blocks classrooms_impr_blocks classrooms_def_cement classrooms_prov_cement classrooms_impr_cement classrooms_def_other classrooms_prov_other classrooms_impr_other), missing

lab var classrooms_def 		"Number of classrooms with definite structure"
lab var classrooms_prov 	"Number of classrooms with provisional structure"
lab var classrooms_impr		"Number of classrooms with improvised structure"
lab var classrooms 			"Number of classrooms in total"

order classrooms_def classrooms_prov classrooms_impr classrooms, after(classrooms_impr_other)

****************************************
************** QUADRO8B ****************
****************************************

foreach var in n_carteiras_1 n_carteiras_2 n_carteiras_3 n_assentos_lugares_1 n_assentos_lugares_2 n_assentos_lugares_3{
replace `var' = . if inlist(`var',999,9999)
}

label variable n_carteiras_1 "Number of individual student desks"
label variable n_carteiras_2 "Number of double student desks"
label variable n_carteiras_3 "Number of student desks with more than 2 seats"


label variable n_assentos_lugares_1 "Number of seats ind. desk"
label variable n_assentos_lugares_2 "Number of seats double desk"
label variable n_assentos_lugares_3 "Number of seats desks with more than 2 seats"


rename n_carteiras_1 			desks_ind
rename n_carteiras_2 			desks_double
rename n_carteiras_3 			desks_more

rename n_assentos_lugares_1 	seats_ind
rename n_assentos_lugares_2 	seats_double
rename n_assentos_lugares_3 	seats_more

egen desks = rowtotal(desks_ind desks_double desks_more), missing
egen seats = rowtotal(seats_ind seats_double seats_more), missing

order desks seats, after(seats_more)

lab var desks  			"Number of student desks"
lab var seats 			"Number of seats"


replace ar_livre = 0 if ar_livre==99 & quadros!=99

foreach var in ar_livre quadros secretarias{
replace `var' = . if `var'==99
}

label variable ar_livre "Number of classes outside"
label variable quadros  "Number of chalkboards"
label variable secretarias "Number of teacher desks"

rename ar_livre 	outside_classes
rename quadros 		chalkboards
rename secretarias	teacher_desks

foreach var in outside_classes chalkboards teacher_desks{
replace `var' = . if `var'==99
}


***************************************
************** QUADRO9 *****************
****************************************

foreach var in manu_prof_ini_1 manu_prof_ini_2 manu_prof_ini_3 manu_prof_ini_4 manu_prof_ini_5 manu_alu_ini_1 manu_alu_ini_2 manu_alu_ini_3 manu_alu_ini_4 manu_alu_ini_5 manu_prof_1_1 manu_prof_1_2 manu_prof_1_3 manu_prof_1_4 manu_prof_1_5 manu_alu_1_1 manu_alu_1_2 manu_alu_1_3 manu_alu_1_4 manu_alu_1_5 manu_prof_2_1 manu_prof_2_2 manu_prof_2_3 manu_prof_2_4 manu_prof_2_5 manu_alu_2_1 manu_alu_2_2 manu_alu_2_3 manu_alu_2_4 manu_alu_2_5 manu_prof_3_1 manu_prof_3_2 manu_prof_3_3 manu_prof_3_4 manu_prof_3_5 manu_alu_3_1 manu_alu_3_2 manu_alu_3_3 manu_alu_3_4 manu_alu_3_5 manu_prof_4_1 manu_prof_4_2 manu_prof_4_3 manu_prof_4_4 manu_prof_4_5 manu_alu_4_1 manu_alu_4_2 manu_alu_4_3 manu_alu_4_4 manu_alu_4_5 manu_prof_5_1 manu_prof_5_2 manu_prof_5_3 manu_prof_5_4 manu_prof_5_5 manu_alu_5_1 manu_alu_5_2 manu_alu_5_3 manu_alu_5_4 manu_alu_5_5 manu_prof_6_1 manu_prof_6_2 manu_prof_6_3 manu_prof_6_4 manu_prof_6_5 manu_alu_6_1 manu_alu_6_2 manu_alu_6_3 manu_alu_6_4 manu_alu_6_5{
replace `var' = . if `var'==999
}


rename manu_prof_ini_1 		manu_teacher_pre_1
rename manu_prof_ini_2  	manu_teacher_pre_2
rename manu_prof_ini_3  	manu_teacher_pre_3
rename manu_prof_ini_4  	manu_teacher_pre_5
rename manu_prof_ini_5  	manu_teacher_pre_12
rename manu_alu_ini_1  		manu_student_pre_1
rename manu_alu_ini_2  		manu_student_pre_2
rename manu_alu_ini_3  		manu_student_pre_3
rename manu_alu_ini_4  		manu_student_pre_5
rename manu_alu_ini_5  		manu_student_pre_12

rename manu_prof_1_1  		manu_teacher_g1_1
rename manu_prof_1_2  		manu_teacher_g1_2
rename manu_prof_1_3  		manu_teacher_g1_3
rename manu_prof_1_4  		manu_teacher_g1_5
rename manu_prof_1_5  		manu_teacher_g1_12
rename manu_alu_1_1  		manu_student_g1_1
rename manu_alu_1_2  		manu_student_g1_2
rename manu_alu_1_3  		manu_student_g1_3
rename manu_alu_1_4  		manu_student_g1_5
rename manu_alu_1_5  		manu_student_g1_12

rename manu_prof_2_1  		manu_teacher_g2_1
rename manu_prof_2_2  		manu_teacher_g2_2
rename manu_prof_2_3  		manu_teacher_g2_3
rename manu_prof_2_4  		manu_teacher_g2_5
rename manu_prof_2_5  		manu_teacher_g2_12
rename manu_alu_2_1  		manu_student_g2_1
rename manu_alu_2_2  		manu_student_g2_2
rename manu_alu_2_3  		manu_student_g2_3
rename manu_alu_2_4  		manu_student_g2_5
rename manu_alu_2_5  		manu_student_g2_12

rename manu_prof_3_1  		manu_teacher_g3_1
rename manu_prof_3_2  		manu_teacher_g3_2
rename manu_prof_3_3  		manu_teacher_g3_3
rename manu_prof_3_4  		manu_teacher_g3_5
rename manu_prof_3_5  		manu_teacher_g3_12
rename manu_alu_3_1  		manu_student_g3_1
rename manu_alu_3_2  		manu_student_g3_2
rename manu_alu_3_3  		manu_student_g3_3
rename manu_alu_3_4  		manu_student_g3_5
rename manu_alu_3_5  		manu_student_g3_12

rename manu_prof_4_1  		manu_teacher_g4_1
rename manu_prof_4_2  		manu_teacher_g4_2
rename manu_prof_4_3  		manu_teacher_g4_3
rename manu_prof_4_4  		manu_teacher_g4_5
rename manu_prof_4_5  		manu_teacher_g4_12
rename manu_alu_4_1  		manu_student_g4_1
rename manu_alu_4_2  		manu_student_g4_2
rename manu_alu_4_3  		manu_student_g4_3
rename manu_alu_4_4  		manu_student_g4_5
rename manu_alu_4_5  		manu_student_g4_12

rename manu_prof_5_1  		manu_teacher_g5_1
rename manu_prof_5_2  		manu_teacher_g5_2
rename manu_prof_5_3  		manu_teacher_g5_3
rename manu_prof_5_4  		manu_teacher_g5_5
rename manu_prof_5_5  		manu_teacher_g5_12
rename manu_alu_5_1  		manu_student_g5_1
rename manu_alu_5_2  		manu_student_g5_2
rename manu_alu_5_3  		manu_student_g5_3
rename manu_alu_5_4  		manu_student_g5_5
rename manu_alu_5_5  		manu_student_g5_12

rename manu_prof_6_1  		manu_teacher_g6_1
rename manu_prof_6_2  		manu_teacher_g6_2
rename manu_prof_6_3  		manu_teacher_g6_3
rename manu_prof_6_4  		manu_teacher_g6_5
rename manu_prof_6_5  		manu_teacher_g6_12
rename manu_alu_6_1  		manu_student_g6_1
rename manu_alu_6_2  		manu_student_g6_2
rename manu_alu_6_3  		manu_student_g6_3
rename manu_alu_6_4  		manu_student_g6_5
rename manu_alu_6_5			manu_student_g6_12


forval x=1/3{
lab var manu_teacher_pre_`x' "Number of teacher manuals pre-school type`x'"
lab var manu_student_pre_`x' "Number of student manuals pre-school type`x'"
lab var manu_teacher_g1_`x' "Number of teacher manuals grade 1 type`x'"
lab var manu_student_g1_`x' "Number of student manuals grade 1 type`x'"
lab var manu_teacher_g2_`x' "Number of teacher manuals grade 2 type`x'"
lab var manu_student_g2_`x' "Number of student manuals grade 2 type`x'"
lab var manu_teacher_g3_`x' "Number of teacher manuals grade 3 type`x'"
lab var manu_student_g3_`x' "Number of student manuals grade 3 type`x'"
lab var manu_teacher_g4_`x' "Number of teacher manuals grade 4 type`x'"
lab var manu_student_g4_`x' "Number of student manuals grade 4 type`x'"
lab var manu_teacher_g5_`x' "Number of teacher manuals grade 5 type`x'"
lab var manu_student_g5_`x' "Number of student manuals grade 5 type`x'"
lab var manu_teacher_g6_`x' "Number of teacher manuals grade 6 type`x'"
lab var manu_student_g6_`x' "Number of student manuals grade 6 type`x'"
}

lab var manu_teacher_pre_5 "Number of teacher manuals pre-school type5"
lab var manu_student_pre_5 "Number of student manuals pre-school type5"
lab var manu_teacher_g1_5 "Number of teacher manuals grade 1 type5"
lab var manu_student_g1_5 "Number of student manuals grade 1 type5"
lab var manu_teacher_g2_5 "Number of teacher manuals grade 2 type5"
lab var manu_student_g2_5 "Number of student manuals grade 2 type5"
lab var manu_teacher_g3_5 "Number of teacher manuals grade 3 type5"
lab var manu_student_g3_5 "Number of student manuals grade 3 type5"
lab var manu_teacher_g4_5 "Number of teacher manuals grade 4 type5"
lab var manu_student_g4_5 "Number of student manuals grade 4 type5"
lab var manu_teacher_g5_5 "Number of teacher manuals grade 5 type5"
lab var manu_student_g5_5 "Number of student manuals grade 5 type5"
lab var manu_teacher_g6_5 "Number of teacher manuals grade 6 type5"
lab var manu_student_g6_5 "Number of student manuals grade 6 type5"

lab var manu_teacher_pre_12 "Number of teacher manuals pre-school type12"
lab var manu_student_pre_12 "Number of student manuals pre-school type12"
lab var manu_teacher_g1_12 "Number of teacher manuals grade 1 type12"
lab var manu_student_g1_12 "Number of student manuals grade 1 type12"
lab var manu_teacher_g2_12 "Number of teacher manuals grade 2 type12"
lab var manu_student_g2_12 "Number of student manuals grade 2 type12"
lab var manu_teacher_g3_12 "Number of teacher manuals grade 3 type12"
lab var manu_student_g3_12 "Number of student manuals grade 3 type12"
lab var manu_teacher_g4_12 "Number of teacher manuals grade 4 type12"
lab var manu_student_g4_12 "Number of student manuals grade 4 type12"
lab var manu_teacher_g5_12 "Number of teacher manuals grade 5 type12"
lab var manu_student_g5_12 "Number of student manuals grade 5 type12"
lab var manu_teacher_g6_12 "Number of teacher manuals grade 6 type12"
lab var manu_student_g6_12 "Number of student manuals grade 6 type12"

replace manu_student_g6_12 = 1050 if school_id==119

/*
*** Note that:

type 1:		Pre-school card
type 2:		Portuguese language
type 3:		Mathematics

type 5:		Natural science

type 12:	Others

*/

****************************************
************** QUADRO10 ****************
****************************************

label variable campo_para_desporto "School has a sport field"
label variable biblioteca "School has a library"
label variable casa_de_banho "School has a bathroom"
label variable cantina_escolar "School has a canteen"
label variable agua     "School has access to water"
label variable electricidade "School has access to electricity"

rename campo_para_desporto 			sportfield
rename biblioteca 					library
rename casa_de_banho 				bathroom
rename cantina_escolar 				canteen
rename agua 						water
rename electricidade				electricity

order canteen, after(bathroom)

foreach var in sportfield library bathroom water electricity canteen{
replace `var' = . if `var'==9
}



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

replace date_year = 2016

drop version school_name number_periods

drop students_pre_age5 students_g1_age5 students_g2_age5 students_g3_age5 students_g4_age5 students_g5_age5 students_g6_age5 girls_pre_age5 girls_g1_age5 girls_g2_age5 girls_g3_age5 girls_g4_age5 girls_g5_age5 girls_g6_age5 students_pre_age6 students_g1_age6 students_g2_age6 students_g3_age6 students_g4_age6 students_g5_age6 students_g6_age6 girls_pre_age6 girls_g1_age6 girls_g2_age6 girls_g3_age6 girls_g4_age6 girls_g5_age6 girls_g6_age6 students_pre_age7 students_g1_age7 students_g2_age7 students_g3_age7 students_g4_age7 students_g5_age7 students_g6_age7 girls_pre_age7 girls_g1_age7 girls_g2_age7 girls_g3_age7 girls_g4_age7 girls_g5_age7 girls_g6_age7 students_pre_age8 students_g1_age8 students_g2_age8 students_g3_age8 students_g4_age8 students_g5_age8 students_g6_age8 girls_pre_age8 girls_g1_age8 girls_g2_age8 girls_g3_age8 girls_g4_age8 girls_g5_age8 girls_g6_age8 students_pre_age9 students_g1_age9 students_g2_age9 students_g3_age9 students_g4_age9 students_g5_age9 students_g6_age9 girls_pre_age9 girls_g1_age9 girls_g2_age9 girls_g3_age9 girls_g4_age9 girls_g5_age9 girls_g6_age9 students_pre_age10 students_g1_age10 students_g2_age10 students_g3_age10 students_g4_age10 students_g5_age10 students_g6_age10 girls_pre_age10 girls_g1_age10 girls_g2_age10 girls_g3_age10 girls_g4_age10 girls_g5_age10 girls_g6_age10 students_pre_age11 students_g1_age11 students_g2_age11 students_g3_age11 students_g4_age11 students_g5_age11 students_g6_age11 girls_pre_age11 girls_g1_age11 girls_g2_age11 girls_g3_age11 girls_g4_age11 girls_g5_age11 girls_g6_age11 students_pre_age12 students_g1_age12 students_g2_age12 students_g3_age12 students_g4_age12 students_g5_age12 students_g6_age12 girls_pre_age12 girls_g1_age12 girls_g2_age12 girls_g3_age12 girls_g4_age12 girls_g5_age12 girls_g6_age12 students_pre_age13 students_g1_age13 students_g2_age13 students_g3_age13 students_g4_age13 students_g5_age13 students_g6_age13 girls_pre_age13 girls_g1_age13 girls_g2_age13 girls_g3_age13 girls_g4_age13 girls_g5_age13 girls_g6_age13 students_pre_age14 students_g1_age14 students_g2_age14 students_g3_age14 students_g4_age14 students_g5_age14 students_g6_age14 girls_pre_age14 girls_g1_age14 girls_g2_age14 girls_g3_age14 girls_g4_age14 girls_g5_age14 girls_g6_age14

drop periods_pre periods_g1 periods_g2 periods_g3 periods_g4 periods_g5 periods_g6

order 	school_id 											/// School ID
		date_day date_month date_year						/// Date
		classes_pre classes_g1 classes_g2 classes_g3 		/// Classes
		classes_g4 classes_g5 classes_g6 classes			///
		students_pre students_g1 students_g2 students_g3 	/// Students
		students_g4 students_g5 students_g6 students		///
		girls_pre  girls_g1  girls_g2  girls_g3  girls_g4  	/// Female students
		girls_g5  girls_g6 girls							///
		repeaters_g1 repeaters_g2 repeaters_g3 repeaters_g4 /// Repeaters
		repeaters_g5 repeaters_g6 repeaters					///
		repeatgirl_g1 repeatgirl_g2 repeatgirl_g3 			/// Female repeaters
		repeatgirl_g4 repeatgirl_g5 repeatgirl_g6 			///
		repeatgirl											///
		disabled_pre disabled_g1 disabled_g2 disabled_g3 	/// Disabled students
		disabled_g4 disabled_g5 disabled_g6					///
		disabled_visual disabled_audio disabled_motor 		///
		disabled_other disabled								///
		disabgirl_pre disabgirl_g1 disabgirl_g2 			/// Female disabled students
		disabgirl_g3 disabgirl_g4 disabgirl_g5 				///
		disabgirl_g6 disabgirl_visual disabgirl_audio 		///
		disabgirl_motor disabgirl_other disabgirl			///
		teachers_pre teachers_prim teachers 				/// Teachers
		teachers_share_uni									///
		teachfem_pre teachfem_prim teachfem 				/// Female Teachers
		teachfem_share_uni									///
		secretaries guards cleaners other_teachers 			/// Staff
		other_empl											///
		secretaries_fem guards_fem cleaners_fem 			/// Female staff
		other_teachers_fem other_empl_fem					///
		classrooms_def_blocks classrooms_prov_blocks 		/// Classrooms
		classrooms_impr_blocks classrooms_def_cement 		///
		classrooms_prov_cement classrooms_impr_cement 		///
		classrooms_def_other classrooms_prov_other 			///
		classrooms_impr_other classrooms_def 				///
		classrooms_prov classrooms_impr classrooms			///
		desks seats chalkboards teacher_desks				/// Furniture
		highest_grade sportfield outside_classes 			/// Other characteristics
		bathroom canteen water electricity					///

drop library period_hours director_name director_age director_tel director_edu director_spec deputy_name deputy_edu deputy_spec director_hoursdir deputy_hoursdir director_hoursteach deputy_hoursteach disabled_visual_pre disabled_visual_g1 disabled_visual_g2 disabled_visual_g3 disabled_visual_g4 disabled_visual_g5 disabled_visual_g6 disabgirl_visual_pre disabgirl_visual_g1 disabgirl_visual_g2 disabgirl_visual_g3 disabgirl_visual_g4 disabgirl_visual_g5 disabgirl_visual_g6 disabled_audio_pre disabled_audio_g1 disabled_audio_g2 disabled_audio_g3 disabled_audio_g4 disabled_audio_g5 disabled_audio_g6 disabgirl_audio_pre disabgirl_audio_g1 disabgirl_audio_g2 disabgirl_audio_g3 disabgirl_audio_g4 disabgirl_audio_g5 disabgirl_audio_g6 disabled_motor_pre disabled_motor_g1 disabled_motor_g2 disabled_motor_g3 disabled_motor_g4 disabled_motor_g5 disabled_motor_g6 disabgirl_motor_pre disabgirl_motor_g1 disabgirl_motor_g2 disabgirl_motor_g3 disabgirl_motor_g4 disabgirl_motor_g5 disabgirl_motor_g6 disabled_other_pre disabled_other_g1 disabled_other_g2 disabled_other_g3 disabled_other_g4 disabled_other_g5 disabled_other_g6 disabgirl_other_pre disabgirl_other_g1 disabgirl_other_g2 disabgirl_other_g3 disabgirl_other_g4 disabgirl_other_g5 disabgirl_other_g6 nivprof_mf_6_ini nivprof_mf_6_ini_2 nivprof_f_6_ini nivprof_f_6_ini_2 nivprof_mf_7x_ini nivprof_mf_7x_ini_2 nivprof_f_7x_ini nivprof_f_7x_ini_2 nivprof_mf_9_ini nivprof_mf_9_ini_2 nivprof_f_9_ini nivprof_f_9_ini_2 nivprof_mf_11_ini nivprof_mf_11_ini_2 nivprof_f_11_ini nivprof_f_11_ini_2 nivprof_mf_bach_ini nivprof_mf_bach_ini_2 nivprof_f_bach_ini nivprof_f_bach_ini_2 nivprof_mf_lic_ini nivprof_mf_lic_ini_2 nivprof_f_lic_ini nivprof_f_lic_ini_2 nivprof_mf_6 nivprof_mf_6_2 nivprof_f_6 nivprof_f_6_2 nivprof_mf_7x nivprof_mf_7x_2 nivprof_f_7x nivprof_f_7x_2 nivprof_mf_9 nivprof_mf_9_2 nivprof_f_9 nivprof_f_9_2 nivprof_mf_11 nivprof_mf_11_2 nivprof_f_11 nivprof_f_11_2 nivprof_mf_bach nivprof_mf_bach_2 nivprof_f_bach nivprof_f_bach_2 nivprof_mf_lic nivprof_mf_lic_2 nivprof_f_lic nivprof_f_lic_2 teachers_age18_pre teachers_age20_pre teachers_age25_pre teachers_age30_pre teachers_age35_pre teachers_age40_pre teachfem_age18_pre teachfem_age20_pre teachfem_age25_pre teachfem_age30_pre teachfem_age35_pre teachfem_age40_pre teachers_age18_prim teachers_age20_prim teachers_age25_prim teachers_age30_prim teachers_age35_prim teachers_age40_prim teachfem_age18_prim teachfem_age20_prim teachfem_age25_prim teachfem_age30_prim teachfem_age35_prim teachfem_age40_prim desks_ind desks_double desks_more seats_ind seats_double seats_more manu_teacher_pre_1 manu_teacher_pre_2 manu_teacher_pre_3 manu_teacher_pre_5 manu_teacher_pre_12 manu_student_pre_1 manu_student_pre_2 manu_student_pre_3 manu_student_pre_5 manu_student_pre_12 manu_teacher_g1_1 manu_teacher_g1_2 manu_teacher_g1_3 manu_teacher_g1_5 manu_teacher_g1_12 manu_student_g1_1 manu_student_g1_2 manu_student_g1_3 manu_student_g1_5 manu_student_g1_12 manu_teacher_g2_1 manu_teacher_g2_2 manu_teacher_g2_3 manu_teacher_g2_5 manu_teacher_g2_12 manu_student_g2_1 manu_student_g2_2 manu_student_g2_3 manu_student_g2_5 manu_student_g2_12 manu_teacher_g3_1 manu_teacher_g3_2 manu_teacher_g3_3 manu_teacher_g3_5 manu_teacher_g3_12 manu_student_g3_1 manu_student_g3_2 manu_student_g3_3 manu_student_g3_5 manu_student_g3_12 manu_teacher_g4_1 manu_teacher_g4_2 manu_teacher_g4_3 manu_teacher_g4_5 manu_teacher_g4_12 manu_student_g4_1 manu_student_g4_2 manu_student_g4_3 manu_student_g4_5 manu_student_g4_12 manu_teacher_g5_1 manu_teacher_g5_2 manu_teacher_g5_3 manu_teacher_g5_5 manu_teacher_g5_12 manu_student_g5_1 manu_student_g5_2 manu_student_g5_3 manu_student_g5_5 manu_student_g5_12 manu_teacher_g6_1 manu_teacher_g6_2 manu_teacher_g6_3 manu_teacher_g6_5 manu_teacher_g6_12 manu_student_g6_1 manu_student_g6_2 manu_student_g6_3 manu_student_g6_5 manu_student_g6_12

rename * A16_*
rename A16_school_id school_id

save "$Baseline_dtRaw/_intermediate files/admin16.dta", replace

********************************************************************************
********************************************************************************
